<template>
  <div>
    <div style="margin: 10px 0">
      <el-input
          style="width: 180px"
          placeholder="请输入资产编号"
          suffix-icon="el-icon-search"
          v-model="assetNumber"
      ></el-input>
      <el-select v-model="assetStates" placeholder="选择状态" style="width: 200px" clearable>
        <el-option
            v-for="item in states" :key="item" :label="item" :value="item"/>
      </el-select>
      <el-button class="ml-5" type="primary" @click="load">搜索</el-button>
      <el-button type="warning" @click="reset">重置</el-button>
      <el-button
          type="primary"
          @click="exp"
          class="ml-5"
      >导出 <i class="el-icon-download"></i
      ></el-button>
    </div>

    <el-table :data="tableData" border stripe style="width: 100%">
      <el-table-column prop="assetId" label="ID" width="80"></el-table-column>
      <el-table-column prop="assetNumber" label="资产编号" width="200">
      </el-table-column>
      <el-table-column prop="name" label="设备名称"></el-table-column>
      <el-table-column prop="type" label="设备类型"></el-table-column>
      <el-table-column label="设备图片" width="150" class-name="image-column">
        <template slot-scope="scope">
          <img :src="local+scope.row.picture" alt="Image"/>
        </template>
      </el-table-column>
      <el-table-column prop="price" label="价格" width="120"></el-table-column>
      <el-table-column prop="ueser" label="使用人" width="120"></el-table-column>
      <el-table-column prop="assetState" label="状态" width="120">
      </el-table-column>
    </el-table>
    <div style="padding: 10px 0">
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageNum"
          :page-sizes="[5, 10, 20]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>


<script>
import {LocalHost, SysStates} from "@/utils/tools";

export default {
  data() {
    return {
      local:LocalHost,
      total: 0,
      tableData: [],
      pageNum: 1,
      pageSize: 5,
      assetNumber: null,
      assetStates: null,
      states: SysStates,
    };
  },
  created() {
    this.load();
  },
  methods: {
    load() {
      this.request
          .get("/information/page", {
            params: {
              pageNum: this.pageNum,
              pageSize: this.pageSize,
              assetNumber: this.assetNumber,
              state: this.assetStates,
            },
          })
          .then((res) => {
            if (res.success) {
              this.tableData = res.data.records;
              this.total = res.data.total;
            }
          });
    },
    handleSizeChange(pageSize) {
      this.pageSize = pageSize;
      this.load();
    },
    handleCurrentChange(pageNum) {
      this.pageNum = pageNum;
      this.load();
    },
    reset() {
      this.assetNumber = "";
      this.assetStates = null;
      this.load();
    },
    exp() {
      window.open(LocalHost + "/information/export");
    },
  },
};
</script>

<style scoped>
.image-column img {
  width: 120px; /* 设置图片宽度 */
  height: 120px; /* 设置图片高度 */
}
</style>